from fastapi import APIRouter, Depends, Request
from sqlalchemy.ext.asyncio import AsyncSession

from config.get_db import get_db
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.service.login_service import LoginService
from module_stock.entity.vo.stat_stock_vo import StatStockPageQueryModel
from module_stock.service.stat_stock_service import StatStockService
from utils.log_util import logger
from utils.page_util import PageResponseModel
from utils.response_util import ResponseUtil

statStockController = APIRouter(prefix='/stock/stat_stock', dependencies=[Depends(LoginService.get_current_user)])


@statStockController.get(
    '/list', response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('stock:stat_stock:list'))]
)
async def get_stat_stock_list(
        request: Request,
        stat_stock_page_query: StatStockPageQueryModel = Depends(StatStockPageQueryModel.as_query),
        query_db: AsyncSession = Depends(get_db),
):
    # 获取分页数据
    stat_stock_page_query_result = await StatStockService.get_stat_stock_list_services(query_db, stat_stock_page_query,
                                                                                       is_page=True)
    logger.info('获取成功')

    return ResponseUtil.success(model_content=stat_stock_page_query_result)


@statStockController.post('/amount_by_tag')
async def get_stat_stock_amount_by_account_tag(
        request: Request,
        query_db: AsyncSession = Depends(get_db)
):
    """
    根据账号标签统计清仓股票资金总和
    """
    result = await StatStockService.get_stat_stock_amount_by_account_tag_services(query_db)
    logger.info('按账号标签统计清仓股票资金总和成功')
    return ResponseUtil.success(data=result)
